{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.keys import Keys\n",
    "from selenium.webdriver.common.action_chains import ActionChains\n",
    "from selenium.webdriver.support.select import Select\n",
    "import time\n",
    "driver = webdriver.Chrome()\n",
    "driver.get(\"http://172.16.184.169:8000/\")\n",
    "\n",
    "driver.find_element_by_link_text(\"登录\").click()\n",
    "driver.find_element_by_id(\"id_username\").send_keys(\"何广良\")\n",
    "driver.find_element_by_id(\"id_password\").send_keys(\"hgl141592\")\n",
    "driver.find_element_by_tag_name(\"button\").click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [],
   "source": [
    "driver.find_element_by_link_text(\"高级功能\").click()\n",
    "driver.find_element_by_link_text(\"高级自主查询\").click()\n",
    "driver.find_element_by_id(\"tableSet4\").click()\n",
    "driver.find_element_by_id(\"textareaSubmit\").click()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [],
   "source": [
    "Options1 = Select(driver.find_element_by_id('plot_highcharts_class')).options\n",
    "plot_select1 = Select(driver.find_element_by_id(\"plot_highcharts_class\"))\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "plot_select1.select_by_index(\"1\")\n",
    "plot_select2 = driver.find_element_by_id('plot_highcharts_model')\n",
    "Options2 = Select(plot_select2).options\n",
    "for i in range(1,len(Options2)):\n",
    "    Select(plot_select2).select_by_index(\"{}\".format(i))\n",
    "    plot_select3 = driver.find_element_by_class_name('plot_highcharts_field')\n",
    "    Options3 = Select(plot_select3).options\n",
    "    for j in range(1,len(Options3)):\n",
    "        Select(plot_select3).select_by_index(\"{}\".format(j))\n",
    "        driver.find_element_by_id(\"plotShow\").click()\n",
    "        time.sleep(2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": true
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "ename": "NoSuchWindowException",
     "evalue": "Message: no such window: target window already closed\nfrom unknown error: web view not found\n  (Session info: chrome=83.0.4103.61)\n",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mNoSuchWindowException\u001B[0m                     Traceback (most recent call last)",
      "\u001B[0;32m<ipython-input-4-4bacfc9af189>\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[1;32m     23\u001B[0m                     \u001B[0mSelect\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mplot_field2\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mselect_by_index\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m\"{}\"\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mformat\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mm\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     24\u001B[0m                     \u001B[0;32mfor\u001B[0m \u001B[0mn\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mrange\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;36m1\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mlen\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mfieldOptions3\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 25\u001B[0;31m                         \u001B[0mSelect\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mplot_field3\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mselect_by_index\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m\"{}\"\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mformat\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mn\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m     26\u001B[0m                         \u001B[0mdriver\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mfind_element_by_id\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m\"plotShow\"\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mclick\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     27\u001B[0m                         \u001B[0mtime\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0msleep\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;36m2\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/anaconda3/envs/django/lib/python3.6/site-packages/selenium/webdriver/support/select.py\u001B[0m in \u001B[0;36mselect_by_index\u001B[0;34m(self, index)\u001B[0m\n\u001B[1;32m     98\u001B[0m         \u001B[0mmatch\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mstr\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mindex\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     99\u001B[0m         \u001B[0;32mfor\u001B[0m \u001B[0mopt\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0moptions\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 100\u001B[0;31m             \u001B[0;32mif\u001B[0m \u001B[0mopt\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget_attribute\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m\"index\"\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;34m==\u001B[0m \u001B[0mmatch\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    101\u001B[0m                 \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_setSelected\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mopt\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    102\u001B[0m                 \u001B[0;32mreturn\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/anaconda3/envs/django/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py\u001B[0m in \u001B[0;36mget_attribute\u001B[0;34m(self, name)\u001B[0m\n\u001B[1;32m    139\u001B[0m             attributeValue = self.parent.execute_script(\n\u001B[1;32m    140\u001B[0m                 \u001B[0;34m\"return (%s).apply(null, arguments);\"\u001B[0m \u001B[0;34m%\u001B[0m \u001B[0mgetAttribute_js\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 141\u001B[0;31m                 self, name)\n\u001B[0m\u001B[1;32m    142\u001B[0m         \u001B[0;32melse\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    143\u001B[0m             \u001B[0mresp\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_execute\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mCommand\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mGET_ELEMENT_ATTRIBUTE\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m{\u001B[0m\u001B[0;34m'name'\u001B[0m\u001B[0;34m:\u001B[0m \u001B[0mname\u001B[0m\u001B[0;34m}\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/anaconda3/envs/django/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py\u001B[0m in \u001B[0;36mexecute_script\u001B[0;34m(self, script, *args)\u001B[0m\n\u001B[1;32m    634\u001B[0m         return self.execute(command, {\n\u001B[1;32m    635\u001B[0m             \u001B[0;34m'script'\u001B[0m\u001B[0;34m:\u001B[0m \u001B[0mscript\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 636\u001B[0;31m             'args': converted_args})['value']\n\u001B[0m\u001B[1;32m    637\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    638\u001B[0m     \u001B[0;32mdef\u001B[0m \u001B[0mexecute_async_script\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mscript\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m*\u001B[0m\u001B[0margs\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/anaconda3/envs/django/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py\u001B[0m in \u001B[0;36mexecute\u001B[0;34m(self, driver_command, params)\u001B[0m\n\u001B[1;32m    319\u001B[0m         \u001B[0mresponse\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcommand_executor\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mexecute\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdriver_command\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mparams\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    320\u001B[0m         \u001B[0;32mif\u001B[0m \u001B[0mresponse\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 321\u001B[0;31m             \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0merror_handler\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcheck_response\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mresponse\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    322\u001B[0m             response['value'] = self._unwrap_value(\n\u001B[1;32m    323\u001B[0m                 response.get('value', None))\n",
      "\u001B[0;32m~/anaconda3/envs/django/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py\u001B[0m in \u001B[0;36mcheck_response\u001B[0;34m(self, response)\u001B[0m\n\u001B[1;32m    240\u001B[0m                 \u001B[0malert_text\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mvalue\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m'alert'\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m'text'\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    241\u001B[0m             \u001B[0;32mraise\u001B[0m \u001B[0mexception_class\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mmessage\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mscreen\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mstacktrace\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0malert_text\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 242\u001B[0;31m         \u001B[0;32mraise\u001B[0m \u001B[0mexception_class\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mmessage\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mscreen\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mstacktrace\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    243\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    244\u001B[0m     \u001B[0;32mdef\u001B[0m \u001B[0m_value_or_default\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mobj\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mkey\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mdefault\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;31mNoSuchWindowException\u001B[0m: Message: no such window: target window already closed\nfrom unknown error: web view not found\n  (Session info: chrome=83.0.4103.61)\n"
     ]
    }
   ],
   "source": [
    "plot_select1.select_by_index(\"2\")\n",
    "plot_model1 = driver.find_element_by_id('plot_highcharts_model1')\n",
    "modelOptions1 = Select(plot_model1).options\n",
    "plot_model2 = driver.find_element_by_id('plot_highcharts_model2')\n",
    "modelOptions2 = Select(plot_model2).options\n",
    "plot_model3 = driver.find_element_by_id('plot_highcharts_model3')\n",
    "modelOptions3 = Select(plot_model3).options\n",
    "for i in range(1, len(modelOptions1)):\n",
    "    Select(plot_model1).select_by_index(\"{}\".format(i))\n",
    "    for j in range(1, len(modelOptions2)):\n",
    "        Select(plot_model2).select_by_index(\"{}\".format(j))\n",
    "        for k in range(1, len(modelOptions3)):\n",
    "            Select(plot_model3).select_by_index(\"{}\".format(k))\n",
    "            plot_field1 = driver.find_element_by_css_selector('select#plot_highcharts_model1+label+select')\n",
    "            fieldOptions1 = Select(plot_field1).options\n",
    "            plot_field2 = driver.find_element_by_css_selector('select#plot_highcharts_model2+label+select')\n",
    "            fieldOptions2 = Select(plot_field2).options\n",
    "            plot_field3 = driver.find_element_by_css_selector('select#plot_highcharts_model3+label+select')\n",
    "            fieldOptions3 = Select(plot_field3).options\n",
    "            for l in range(1, len(fieldOptions1)):\n",
    "                Select(plot_field1).select_by_index(\"{}\".format(l))\n",
    "                for m in range(1, len(fieldOptions2)):\n",
    "                    Select(plot_field2).select_by_index(\"{}\".format(m))\n",
    "                    for n in range(1, len(fieldOptions3)):\n",
    "                        Select(plot_field3).select_by_index(\"{}\".format(n))\n",
    "                        driver.find_element_by_id(\"plotShow\").click()\n",
    "                        time.sleep(2)\n",
    "                        # driver.find_element_by_id(\"scatter_remove_abnormal\").click()\n",
    "                        # driver.find_element_by_id(\"plotShow\").click()\n",
    "                        # time.sleep(5)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [],
   "source": [
    "plot_select1.select_by_index(\"2\")\n",
    "driver.find_element_by_id(\"scatter_remove_abnormal\").click()\n",
    "plot_model1 = driver.find_element_by_id('plot_highcharts_model1')\n",
    "plot_model2 = driver.find_element_by_id('plot_highcharts_model2')\n",
    "plot_model3 = driver.find_element_by_id('plot_highcharts_model3')\n",
    "allOption = {\n",
    "    \"样本临床信息\": ['性别', '年龄', '医院编号'],\n",
    "    \"样本DNA提取信息\": ['浓度(ng/ul)'],\n",
    "    \"样本建库信息\": ['建库日期', '建库方法', '建库-操作人'],\n",
    "    \"捕获文库信息\": ['杂交日期', '杂交探针', '捕获文库-PostPCR浓度(ng/ul)'],\n",
    "    \"测序上机信息\": ['下机时间']\n",
    "}\n",
    "model_list = [\"样本临床信息\", \"样本DNA提取信息\", \"样本建库信息\", \"测序上机信息\"]\n",
    "for i in [0, 1, 2, 3]:\n",
    "    Select(plot_model1).select_by_visible_text(model_list[i])\n",
    "    for j in [1, 2, 3, 0]:\n",
    "        Select(plot_model2).select_by_visible_text(model_list[j])\n",
    "        for k in [2, 3,0, 1]:\n",
    "            Select(plot_model3).select_by_visible_text(model_list[k])\n",
    "\n",
    "            plot_field1 = driver.find_element_by_css_selector('select#plot_highcharts_model1+label+select')\n",
    "            fieldOptions1 = allOption[model_list[i]]\n",
    "            plot_field2 = driver.find_element_by_css_selector('select#plot_highcharts_model2+label+select')\n",
    "            fieldOptions2 = allOption[model_list[j]]\n",
    "            plot_field3 = driver.find_element_by_css_selector('select#plot_highcharts_model3+label+select')\n",
    "            fieldOptions3 = allOption[model_list[k]]\n",
    "            for l in fieldOptions1:\n",
    "                Select(plot_field1).select_by_visible_text(l)\n",
    "                for m in fieldOptions2:\n",
    "                    Select(plot_field2).select_by_visible_text(m)\n",
    "                    for n in fieldOptions3:\n",
    "                        if n=='癌种':\n",
    "                            continue\n",
    "                        Select(plot_field3).select_by_visible_text(n)\n",
    "                        driver.find_element_by_id(\"plotShow\").click()\n",
    "                        time.sleep(2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---\n",
      "样本临床信息\n",
      "样本DNA提取信息\n",
      "样本DNA使用记录\n",
      "样本DNA库存\n",
      "样本建库信息\n",
      "捕获文库信息\n",
      "Pooling映射表\n",
      "测序上机信息\n",
      "样本测序质控信息\n"
     ]
    }
   ],
   "source": [
    "plot_model1 = driver.find_element_by_id('plot_highcharts_model1')\n",
    "print(plot_model1.text)\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}